# Contributor: Milan P. Stanić <mps@arvanta.net>
# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Milan P. Stanić <mps@arvanta.net>
pkgname=iwd
pkgver=3.0
pkgrel=0
pkgdesc="Internet Wireless Daemon"
url="https://iwd.wiki.kernel.org/"
arch="all"
license="LGPL-2.1-or-later"
depends="dbus"
makedepends="dbus-dev readline-dev linux-headers"
options="!check" # some builders fail on some test
checkdepends="coreutils"
subpackages="
	$pkgname-dbg
	$pkgname-doc
	$pkgname-openrc
	ead
	ead-openrc:ead_openrc:noarch
	"
source="https://mirrors.edge.kernel.org/pub/linux/network/wireless/iwd-$pkgver.tar.gz
	0001-resolving-service-none.patch

	iwd.initd
	iwd.confd
	ead.initd
	ead.confd
	main.conf
	"

# secfixes:
#   2.14-r0:
#     - CVE-2023-52161

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--localstatedir=/var \
		--disable-systemd-service \
		--enable-wired \
		--enable-tools
	make
}

check() {
	make check
}

package() {
	make DESTDIR="$pkgdir" install

	install -m750 -d "$pkgdir"/var/lib/$pkgname
	install -m644 -D "$srcdir"/main.conf "$pkgdir"/etc/$pkgname/main.conf

	install -m755 -D "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
	install -m644 -D "$srcdir"/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname
}

ead() {
	pkgdesc="Ethernet authentication daemon"

	amove usr/libexec/ead
	amove usr/share/dbus-1/system.d/ead-dbus.conf

	install -m750 -d "$subpkgdir"/etc/ead
	# ead expects configs in /var/lib/ead, but these are really configs,
	# not dynamically generated, so they should be in /etc.
	mkdir -p "$subpkgdir"/var/lib
	ln -s /etc/ead "$subpkgdir"/var/lib/ead
}

ead_openrc() {
	pkgdesc="Ethernet authentication daemon (OpenRC init scripts)"
	depends=""
	install_if="openrc ead=$pkgver-r$pkgrel"

	install -m755 -D "$srcdir"/ead.initd "$subpkgdir"/etc/init.d/ead
	install -m644 -D "$srcdir"/ead.confd "$subpkgdir"/etc/conf.d/ead
}

sha512sums="
0998891aebabf01d4810e88524c056dec56964f7d71725f3ed89b68e697f29202aae38347356de44d54090c3975a26058a4d96597dc722b058779243a72cea39  iwd-3.0.tar.gz
dc7e8ab038b5402573ee41d00b016a3faa172fe260dd7c59d567ae0d933e5a5688aac9f0b8d4089a6b13b1a320540423182d13b3dca1cd3de17f59ae3e5f4df1  0001-resolving-service-none.patch
ae697a2b5647f6f8b21902eb7e9a9ec02996be6d4f9cdec162f5423f4cebf83cdb9a137d1a95d085485ec3a7b16c1f0377fabdbb4cc28b9628742201b4503fc2  iwd.initd
c53bfe1b18f0e965d6055e79b40d9f01d13648a4ae6124d2bcb0c6a77dc16f96980df0127c67cecd2a0319a6052f980400bb063d00c87ec016ccb350e3fe797e  iwd.confd
8207a411d400bc7932829c959251a3246d1c33d342afa7070023dc90403e58b19518b2c84fe36495075a44724e2deab38970a2cc1f83bfff5abf3dff54b8ea3f  ead.initd
4611df202e07178556d61f5642ea82f56cafaee9bf122240d8de8b4937b6bd3458ee7c2d209211523febab942dee184e94c899a1fd4456f8357347030c943c49  ead.confd
fd9d19bd29ad9c78653c5c38da3ee739ccdc0e8fdcbb041b6ee1674e5f2bd6461122a12ff46895252b409a70e62a117f4e1950cbb3c578a25b0ae6c6874823b7  main.conf
"
